<template>
  <c-dialog ref="dialog" :open-fun="openFun" title="图纸设计日志" @open="openHandle" @closed="closedHandle">
    <c-list ref="form" :model="formData" :rules="formRules" label-width="100px">
      <c-list-item label="图纸设计日志" prop="designLog">
        <el-input v-model="formData.designLog" type="textarea" maxlength="1024" show-word-limit :autosize="{minRows:3}" placeholder="审核意见" clearable />
      </c-list-item>
      <c-list-item>
        <div class="btn-container">
          <c-button @click="cancelHandle">取消</c-button>
          <c-button key="confirm" type="primary" @click="confirmHandle">确认</c-button>
        </div>
      </c-list-item>
    </c-list>
  </c-dialog>
</template>
<script>
import { designLogEdit } from '@/api/shopDrawing'
export default {
  name: 'DesignLog',
  components: {
  },
  props: {
    selData: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      formData: {
        designLog: ''
      },
      formRules: {
        designLog: [{ required: true, message: '请填写图纸设计日志', trigger: 'change' }]
      }
    }
  },
  computed: {
    detail() {
      return this.selData.length === 0 ? {} : this.selData[0]
    }
  },
  methods: {
    // 规则：（1）单选异常暂停的数据可编辑图纸设计日志信息；（2）选择数据后弹出文本框填写相关内容
    openFun() {
      if (!this.singleJudge(this.selData, '图纸设计日志', true)) {
        return false
      }
      const d = this.selData[0]
      if (d.state !== 'ABNORMAL') {
        this.$message.warning('异常暂停的图纸，才能编辑图纸设计日志')
        return false
      }
      return true
    },
    openHandle() {
      this.$set(this.formData, 'designLog', this.detail.designLog || '')
    },
    closedHandle() {
      this.$set(this.formData, 'designLog', '')
    },
    confirmHandle() {
      return this.$refs.form.validate().then(() => {
        return designLogEdit(this.detail.id, this.formData.designLog).then(res => {
          this.$message.success('操作成功！')
          this.$refs.dialog.visible = false
          this.$emit('on-success')
        })
      })
    },
    cancelHandle() {
      this.$refs.dialog.visible = false
      this.$set(this.formData, 'designLog', '')
    }
  }
}
</script>
